package com.bwie.parkdemo.mvvm.model;

import com.bwie.lib_core.base.BaseEntity;
import com.bwie.lib_core.mvvm.base.BaseModel;
import com.bwie.lib_core.network.HttpRetrofitFactory;
import com.bwie.lib_core.network.HttpType;
import com.bwie.parkdemo.mvvm.model.entity.LoginEntity;

import java.util.Collections;

import io.reactivex.Observable;
import io.reactivex.functions.Function;
import io.reactivex.internal.functions.Functions;
import okhttp3.RequestBody;

/**
 * 用户登录model
 * */
public class LoginModel extends BaseModel {
    @Override
    public Observable<BaseEntity> request(RequestBody... bodyes) {
        //使用Retrofit构建对应用户登录
        //使用哪个类型的请求方式->HttpType.SIGNINTERFACE->由于当前接口只有sign签名
        //使用只添加sign拦截的建造者建造对应retrofit对象
        //转化为基类的BaseEntity->使用Observable下的flatmap操作符转换
       Observable<LoginEntity> sources = HttpRetrofitFactory.getInstance().
                factory(HttpType.SIGNINTERFACE).getRetrofit()
                .create(Api.class).requestLogin(bodyes[0]);
        Observable<BaseEntity>ob = Observable.fromArray(sources).flatMap((Function) Functions.identity(), false, 1, 1);
        return ob;
    }

    @Override
    public void cleared() {

    }
}
